package com.base;

import java.util.TreeMap;

public class Testinterrupt {
    public  static  void main(String [] args) {

        Thread thread= new Thread(new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName()+"start");

                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    System.out.println("线程中止");//线程终止后报异常
                }
                System.out.println(Thread.currentThread().getName()+"end");

            }
        });
        System.out.println(Thread.currentThread().getName()+"start");

        thread.start();
        try {
            Thread.sleep(2000);
            //thread.interrupt();//中止线程报异常，如果使用stop()，子线程与后面的代码不会执行
            thread.stop();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"end");



    }
}
